home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / c / agl103p.lha / src / prototype / prototype.c < prev    next >
C/C++ Source or Header  |  1994-11-18  |  2KB  |  117 lines

  1. #include<stdio.h>
  2.  
  3. #define AUTOLONG    0 /* TRUE = add long to prototype if type not recognized */
  4.  
  5. #define MATCH 13
  6.  
  7. void abort(void);
  8. int readline(FILE *infile,char *line,char end);
  9.  
  10.  
  11.  
  12. /*PROTOTYPE*/
  13. int main(long argc,char **argv)
  14.     {
  15.     FILE *outfile,*infile;
  16.     char filename[50],proto[150],line[500];
  17.     short filen,c,start=1;
  18.  
  19.     strcpy(proto,"/*PROTOTYPE*/");
  20.  
  21.     if(!strcmp(argv[1],"-o"))
  22.         {
  23.         if(argc<4)
  24.             abort();
  25.  
  26.         start=3;
  27.  
  28.         outfile=fopen(argv[2],"w");
  29.         if(outfile==NULL)
  30.             {
  31.             printf("\nError opening %s for save\n",argv[2]);
  32.             abort();
  33.             }
  34.         }
  35.     else
  36.         outfile=stdout;
  37.  
  38.     if(start>=argc)
  39.         abort();
  40.  
  41.     for(filen=start;filen<argc;filen++)
  42.         {
  43.         strcpy(filename,argv[filen]);
  44.         fprintf(outfile,"/* %s */\n",filename);
  45.  
  46.         infile=fopen(filename,"r");
  47.         if(infile==NULL)
  48.             {
  49.             fprintf(outfile,"\n/* ERROR: Unreadable */\n\n");
  50.             }
  51.         else
  52.             {
  53.             c=0;
  54.             while(c!=EOF)
  55.                 {
  56.                 c=readline(infile,line,(char)'\n');
  57. /*
  58. fprintf(outfile,"SEARCH  %s\n",line);
  59. */
  60.                 if( c!=EOF && !strncmp(line,proto,MATCH) )
  61.                     {
  62.                     c=readline(infile,line,(char)'{');
  63. /*
  64. fprintf(outfile,"COMMENT %s\n",line);
  65. fprintf(outfile,"    ");
  66. */
  67.                     while(line[strlen(line)-1]==' ' || line[strlen(line)-1]=='    ' || line[strlen(line)-1]=='\n')
  68.                         line[strlen(line)-1]=0;
  69.  
  70.                     if(        !AUTOLONG ||                !strncmp(line,"int",3)  ||
  71.                             !strncmp(line,"char",4) ||    !strncmp(line,"short",5)  ||
  72.                             !strncmp(line,"void",4) ||    !strncmp(line,"double",6) ||
  73.                             !strncmp(line,"long",4) ||    !strncmp(line,"float",5)     )
  74.                         fprintf(outfile,"%s;\n",line);
  75.                     else
  76.                         fprintf(outfile,"long  %s;\n",line);
  77.                     }
  78.                 }
  79.             fclose(infile);
  80.             fprintf(outfile,"\n");
  81.             }
  82.         }
  83.  
  84.     return 0;
  85.     }
  86.  
  87.  
  88.  
  89. /*PROTOTYPE*/
  90. void abort(void)
  91.     {
  92.     printf("Usage: prototype [-o outfile] infile [...]\n");
  93.     }
  94.  
  95.  
  96.  
  97. /*PROTOTYPE*/
  98. int readline(FILE *infile,char *line,char end)
  99.     {
  100.     int n,c;
  101.  
  102.     c=0;
  103.     n=0;
  104.     while(c!=EOF && c!=end)
  105.         {
  106.         c=getc(infile);
  107.         if(c!=EOF && c!=end)
  108.             {
  109.             line[n]=c;
  110.             n++;
  111.             }
  112.         }
  113.     line[n]=0;
  114.  
  115.     return c;
  116.     }
  117.